package br.usp.ime.dojo.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class StarterSession extends Composite {
	StarterSessionServiceAsync service;
	VerticalPanel panel;
	Button startSession;
	private StarterSessionListener starterSessionListener;
	private DojoRoomDTO createdRoom;
	
	//@SuppressWarnings("deprecation")
	public StarterSession() {
		service = GWT.create(StarterSessionService.class);
		panel = new VerticalPanel();
		startSession = new Button();
		startSession = new Button("START SESSION");		
		
		startSession.addClickListener(new ClickListener(){

			public void onClick(Widget sender) {
				startSession();
			}			
		});

		panel.add(startSession);		
		initWidget(panel);
	}

	public void startSession() {
		
		AsyncCallback<Void> callback = new AsyncCallback<Void>() {
			public void onFailure(Throwable caught) {
			}

			public void onSuccess(Void nul) {
				starterSessionListener.onClickStartSuccess();
			}
		};
		
		service.onClickStartSession(callback);
		
	}

	public void setStarterSessionListener(StarterSessionListener listener)
	{
		starterSessionListener = listener;
	}
	
	public DojoRoomDTO getCreatedRoom() {
		return createdRoom;
	}
}